import request from "@/libs/request";

const basePath = '/appcloud-dashboard' ;

export const apiUrls = {
    getDashboardInfo : basePath + '/api/dashboard/getDashboardInfo',
    getEthoInfo : basePath + '/api/dashboard/getEthoInfo',
    getLastNetByEtho : basePath + '/api/dashboard/getLastNetByEtho',
    getNetByEtho : basePath + '/api/dashboard/getNetByEtho',
    getNetStat : basePath + '/api/dashboard/getNetStat',
    getSysAlarmInfo : basePath +'/api/dashboard/getSysAlarmInfo'
}

//查询虚机监控信息
export async function getDashboardInfo(params){
	return request( apiUrls.getDashboardInfo , {
      method:'POST',
      body:params
  }).then(ret=>{
  	let data = {}
  	if(ret&&ret.data){
			if(ret.data.cpuUsedPercent){
					// CPU
					var cpuUsedPercent = parseFloat(ret.data.cpuUsedPercent).toFixed(2);
					var cpuUnUsePercent = (100-cpuUsedPercent).toFixed(2);
			}else{
				  cpuUsedPercent = '0';cpuUnUsePercent = '0'
			}
  	
			// 内存
			if(ret.data.memoryUsedPercent){
				var ncUsedPersent = parseFloat(ret.data.memoryUsedPercent).toFixed(2);
				var ncUnUsePersent = (100 - ncUsedPersent).toFixed(2);
			}else{
				ncUsedPersent = 0
				ncUnUsePersent = 0
				ret.data.memoryUsed = '0'
				ret.data.memoryTotal ='0'
			}
	  
			// 磁盘
			if(ret.data.diskUsedPercent){
				var cpUsed = parseFloat(ret.data.diskUsedPercent).toFixed(2);
				var cpUnUsed = (100 - cpUsed).toFixed(2);
			}else{
				cpUsed ='0',
				cpUnUsed = '0',
				ret.data.diskUsed = '0',
				ret.data.diskFree = '0'
			}
	  
	  	data = {
	  		cpuRow : [
	  			{name : `已使用${cpuUsedPercent}%`, value : cpuUsedPercent || "0"},
	  			{name : `未使用${cpuUnUsePercent}%`, value : cpuUnUsePercent || "0"},
	  		],
	  		ncRow : [
	  			{name : `已使用${ret.data.memoryUsed}`, value : ncUsedPersent || "0"},
	  			{name : `未使用${ret.data.memoryFree}`, value : ncUnUsePersent || "0"},
	  		],
	  		cpRow : [
	  			{name : `已使用${ret.data.diskUsed}`, value : cpUsed || "0"},
	  			{name : `未使用${ret.data.diskFree}`, value : cpUnUsed || "0"},
	  		]
	  	}
  	}
  	
  	return data ;
  })
}


//查询虚机网卡信息
export async function getEthoInfo(params){
	return request( apiUrls.getEthoInfo , {
      method:'POST',
      body:params
  })
}


//查询虚机最后一次的监控信息
export async function getLastNetByEtho(params){
	return request( apiUrls.getLastNetByEtho , {
      method:'POST',
      body:params
  })
}
//查询虚机IO信息
export async function getNetByEtho(params){
	return request( apiUrls.getNetByEtho , {
      method:'POST',
      body:params
  })
}
//查询虚机网络状态
export async function getNetStat(params){
	return request( apiUrls.getNetStat , {
      method:'POST',
      body:params
  })
}
//查询系统运行分值及告警项
export async function getSysAlarmInfo(params){
	return request( apiUrls.getSysAlarmInfo , {
      method:'POST',
      body:params
  })
}